<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    :okButtonProps="{ props: {disabled: disableSubmit} }"
    cancelText="关闭"
    okText="确认金额">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="合同信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <span>{{model.leaseContractId_dictText}}</span>
        </a-form-item>
        <a-form-item label="资产信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <span>{{model.assetId_dictText}}</span>
        </a-form-item>

        <a-form-item label="资产明细" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <span>{{model.assetSubIds_dictText}}</span>
        </a-form-item>

        <a-form-item label="客户信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <span>{{model.customerId_dictText}}</span>
        </a-form-item>
        <a-form-item label="款项说明" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <span>{{model.paymentInstructions_dictText}}</span>
        </a-form-item>
        <a-form-item label="收款金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <span>{{model.amountMoney}}</span>
        </a-form-item>
        <a-form-item label="开始日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <span>{{model.startTime}}</span>
        </a-form-item>
        <a-form-item label="结束日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <span>{{model.endTime}}</span>
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol2" :wrapperCol="wrapperCol2">
          <span>{{model.remark}}</span>
        </a-form-item>

        <a-form-item
          label="全部确认"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          :required="true"
          help="该合同的所有收款信息是否都完成确认，按照该标准执行？">
          <a-radio-group v-model="value">
            <a-radio :value="1">否</a-radio>
            <a-radio :value="2">是</a-radio>
          </a-radio-group>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { amountConfirmation } from '@/api/receivables'

  export default {
    name: 'AmountConfirmationModal',
    data () {
      return {
        value: 1,
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        confirmLoading: false,
        isReadOnly: false,
        disableSubmit: false,
      }
    },
    created () {
    },
    methods: {
      show (record) {
        this.form.resetFields()
        this.model = Object.assign({}, record)
        this.visible = true
      },
      close () {
        this.$emit('close')
        this.visible = false
      },
      handleOk () {
        const that = this
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            this.$confirm({
              title: "确认提醒",
              content: "是否确认金额无误?",
              onOk: function () {
                that.confirmLoading = true
                amountConfirmation({ id: that.model.id, isAllConfirmation: that.value }).then((res) => {
                  if (res.success) {
                    that.$message.success(res.message)
                    that.$emit('ok');
                    that.close()
                  } else {
                    that.$message.warning(res.message)
                  }
                }).finally(() => {
                  that.confirmLoading = false

                })
              }
            });
          }

        })

      },
      handleCancel () {
        this.close()
      },
      popupCallback (row) {
        this.form.setFieldsValue(pick(row, 'leaseContractId', 'payeeRemark', 'payeeBy', 'assetId', 'assetSubIds', 'customerId', 'paymentInstructions', 'amountMoney', 'payStatus', 'payType', 'startTime', 'endTime', 'receiptDate', 'remark'))
      }

    }
  }
</script>

<style lang="less" scoped>
  .ant-form-item {
    margin-bottom: 0px;
  }
</style>